package win.demonlegion.util;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;

import java.io.Serializable;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;

/**
 * 后台生成随机数工具类
 * Created by john on 2017/7/4.
 */
public class RandomUtil implements Serializable {
    private static final long serialVersionUID = -9142787188821218444L;

    private static final Random RANDOM = new SecureRandom();
    private static final RandomGenerator randomGenerator = new JDKRandomGenerator();

    public static String getRandomCode(int size) {
        return RandomStringUtils.randomNumeric(size);
    }

    public static int getRandomDelay(int range, int min) {
        return min + randomGenerator.nextInt(range);
    }

    public static String getRandomString(int size) {
        return RandomStringUtils.randomAlphanumeric(size);
    }

    public static BigInteger getRandomPrime(int bitLength) {
        return BigInteger.probablePrime(bitLength, RANDOM);
    }

    public static BigInteger getRandomBigInteger(int bitLength) {
        return new BigInteger(bitLength, RANDOM);
    }
}
